#include<bits/stdc++.h>

using namespace std;

#define endl '\n'

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int T;
    cin >> T;
    while (T--) {
        string s;
        cin >> s;
        transform(s.begin(),
                  s.end(),
                  s.begin(),
                  [](char c) {
                      if (isupper(c))return tolower(c);
                      else return toupper(c);
                  }
        );
        cout << s << endl;
    }

    return 0;
}
